//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：HDMEditor
// *描述：
// *?2021 MYJL . All rights reserved.
//* ======================================================================
using System.IO;
using UnityEditor;
using UnityEngine;
namespace HDMCode.FrameEditor
{
	public class HDMEditorMenuItem:Editor
	{
        //[MenuItem("海盗猫框架/创建包体管理器", false)]
        //public static HDMEditorSetting CreatEditorPacked() => CreatSetting<HDMEditorSetting>(HDMEditorDate.PackedProjectPath, HDMEditorDate.PackedAssetsPath);

        /// <summary>
        /// 创建窗口
        /// </summary>
        [MenuItem("海盗猫框架/工具窗口", false)]
        public static void CreatWin()
        {
            Texture winIcon = AssetDatabase.LoadAssetAtPath<Texture>(HDMEditorDate.GUIIconFileAssetsPath + "/WindowIcon.png");
            HDMEditor.thisWindow = EditorWindow.GetWindow<HDMEditor>();
            HDMEditor.thisWindow.titleContent = new GUIContent("HDM框架管理系统", winIcon, "HDM框架管理系统");
            HDMEditor.thisWindow.minSize = new Vector2(600, 600);
            HDMEditor.thisWindow.maxSize = new Vector2(600, 600);
            HDMEditor.thisWindow.ShowPopup();
        }

        /// <summary>
        /// 创建配置文件
        /// </summary>
        /// <typeparam name="T"> 配置文件类型 </typeparam>
        /// <param name="settingProjectPath"> 配置文件项目类型 </param>
        /// <param name="settingAssetsPath"> 配置文件资源路径 </param>
        /// <returns></returns>
        public static T CreatSetting<T>(string settingProjectPath,string settingAssetsPath) where T : ScriptableObject , new()
        {
            T createSetting = default;
            if (!File.Exists(settingProjectPath)) 
            {
                createSetting = ScriptableObject.CreateInstance<T>();
                AssetDatabase.CreateAsset(createSetting, settingAssetsPath);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                HDMEditorHelper.SeletFile(settingAssetsPath);
            }
            else
            {
                createSetting = AssetDatabase.LoadAssetAtPath<T>(settingAssetsPath);
                HDMEditorHelper.SeletFile(settingAssetsPath);
            }
            return createSetting;
        }
    }
}


